﻿using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyWeb.Extensions.ServiceExtensions.Filter
{
    /// <summary>
    /// 异常筛选器：用于异常处理
    /// </summary>
    public class ExceptionExFilter : IAsyncExceptionFilter
    {
        public Task OnExceptionAsync(ExceptionContext context)
        {
            Console.WriteLine(context.Exception.Message);

            context.Result = new ObjectResult(new
            {
                code = 500,
                message = context.Exception.Message
            });
            return Task.CompletedTask;
        }
    }
}
